﻿using ReservationModule.Classes;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ReservationModule
{
    public partial class UserAccountCreation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["Login"] = Session["Login"];
            if (Session["Login"] == "false" || Session["Login"] == null)
            {
                Response.Redirect("Reject.aspx");
            }

            if (Session["StaffType"] != "Administrator")
            {
                Response.Redirect("Reject.aspx");
            }
        }

        protected void btnGenerateID_Click(object sender, EventArgs e)
        {
           DBManager id = new DBManager();
           tbxStaffID.Text = id.generateStaffID();
        }

        protected void btnCreate_Click(object sender, EventArgs e)
        {

            string staffID = tbxStaffID.Text;
            string password = tbxPassword.Text;
            string staffType = DropDownList1.Text;
            string staffNRIC = tbxNRIC.Text;

            //UserAccount a = new UserAccount(staffID, password, staffType);
            UserAccount a = new UserAccount() { StaffID1 = staffID, Password1 = password, StaffType1 = staffType, StaffNRIC1 = staffNRIC };
            int UserAccountCreation = DBManager.CreateUserAccount(a);
            if (UserAccountCreation == 1)
            {
                Response.Redirect("UserAccountCreationSuccessful.aspx?");
            }
            else
            {
                Label1.Text = "StaffID already exists!";
            }
            

        }

        protected void btnCheck_Click(object sender, EventArgs e)
        {
            string lol = DBManager.check(tbxNRIC.Text);
            if (lol == "ok")
            {
                lblExist.Visible = true;
                lblExist.Text = "Already Exists!";
            }
            if (lol == "no")
            {
                lblExist.Visible = true;
                lblExist.Text = "Staff NRIC does not exist!";
            }
            }

        protected void tbxStaffID_TextChanged(object sender, EventArgs e)
        {

        }
            
        }


    }
